import entity.ActualData;
import utils.DateHandle;
import utils.ExcelReader;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class test {
    public static void main(String[] args) {
        List<ActualData> AllactualData = ExcelReader.readActualData("D:\\idea\\HFHKGY\\src\\main\\resources\\resource\\全年移交数据.xlsx");
        Map<String,List<ActualData>> actualData = AllactualData.stream().collect(Collectors.groupingBy(ActualData::getMonth));
        System.out.println(actualData.size());
        System.out.println("actualData = " + actualData.get("1月份").get(1).getMonth());
        final double[] M = new double[]{0.5321,0.3185};
        final double []alpha =new double[] {-0.3679,-0.4815};
        for (int j = 0; j <=1 ; j++) {
            double totalBeforeTime=0;
            double totalAfterTime=0;
            for (int k = 1; k <=12 ; k++) {
                double time1=0;
                double time2=0;
                for(ActualData actualdata : actualData.get(String.valueOf(k)+"月份")) {
                    int num=actualdata.getInventoryNumber();
                    double time=0;
                    totalBeforeTime+= actualdata.getMakeCycle()*actualdata.getInventoryNumber();
                    time1+=actualdata.getMakeCycle()*actualdata.getInventoryNumber();
                    for (int i = 1; i <=num ; i++) {
                        time+=predictTime(actualdata.getMakeCycle(),alpha[j],M[j],i);
                    }
                    // System.out.println(actualdata.getItemName()+" 数量："+actualdata.getInventoryNumber()+"初始工时： "+actualdata.getTotalTime()+"   "+"优化后工时： "+time);
                    totalAfterTime+=time;
                    time2+=time;

                }
                System.out.println("time1 = " + time1);
                System.out.println("time2 = " + time2);
                System.out.println("alpha = " + alpha[j]);
                System.out.println("M = " + M[j]);
            }
            System.out.println("初始工时为： "+totalBeforeTime+"总需求工时优化后为： "+totalAfterTime);
        }
    }
    public  static double   predictTime(double baseTime, double alpha, double m, int repetition) {
        double learningTerm = m + (1 - m) * Math.pow(repetition, alpha);
        return learningTerm * baseTime;
    }
}
